package com.ftg.learn.boot.controller;

import com.ftg.learn.boot.pojo.Dept;
import com.ftg.learn.boot.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/dd")
@RestController  //controller   responsebody
@CrossOrigin
public class DeptController {

    @Autowired
    DeptService ds;

    @GetMapping("/show")
    public Map<String,Object> showAll(int page,int limit,String deptno, String dname){

        Map<String,Object> map = new HashMap<>();
        List<Dept> list = ds.showAll(page,limit, deptno,dname);
        map.put("data", list);//11 10
        map.put("deptno", deptno);//11 10
        map.put("dname", dname);//11 10

        map.put("code", 0);
        map.put("count", ds.getcount(deptno,dname));
        map.put("msg", "到哪里");
        return map;
    }

    @DeleteMapping("/del/{id}")
    public int deleteDept(@PathVariable int id) {//PathVariable 获取SpringMVC通过地址栏传递的参数
        return ds.delete(id);
    }

    @PostMapping("/update")
    public int update(Dept dept) {
        System.out.println(dept.getDname());
        return ds.update(dept);
    }

    @PostMapping("/add")
    public int add(Dept dept) {
        System.out.println(dept.getDname());
        return ds.add(dept);
    }


}